using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Forms;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Threading;
using Buddy.Coroutines;
using log4net;
using Microsoft.CSharp;
using Microsoft.Win32;
using ns2;
using ns25;
using ns3;
using Triton.Bot;
using Triton.Bot.Settings;
using Triton.Common;
using Triton.Common.LogUtilities;
using Triton.Game;
using Triton.Game.Mapping;

namespace Hearthbuddy.Windows
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	/// <summary>
	/// MainWindow
	/// </summary>
	public partial class MainWindow : Window, IComponentConnector
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class Class25
		{
			public static readonly Class25 Instance9 = new Class25();

			public static Action Instance9__2_0;

			public static EventHandler Instance9__12_2;

			public static Func<Task> Instance9__12_3;

			public static Action<Hotkey> Instance9__12_17;

			public static Func<IPlugin, string> Instance9__17_0;

			public static Func<IPlugin, string> Instance9__18_0;

			internal void method_0()
			{
				System.Windows.Application.Current.Shutdown();
			}

			internal void method_1(object sender, EventArgs e)
			{
				ilog_0.Info("[ProcessExited] The game process has closed. Hearthbuddy will now close.");
				Class12.smethod_0();
				Environment.Exit(0);
			}

			internal Task method_2()
			{
				return smethod_0();
			}

			internal void method_3(Hotkey hotkey_0)
			{
				if (BotManager.IsRunning)
				{
					BotManager.Stop();
				}
				else
				{
					BotManager.Start();
				}
			}

			internal string method_4(IPlugin iplugin_0)
			{
				return iplugin_0.Name;
			}

			internal string method_5(IPlugin iplugin_0)
			{
				return iplugin_0.Name;
			}
		}

		[CompilerGenerated]
		private sealed class Class26
		{
			public string string_0;

			internal bool method_0(IBot ibot_0)
			{
				return ibot_0.Name == string_0;
			}
		}

		[CompilerGenerated]
		private sealed class Class27
		{
			public string string_0;

			internal bool method_0(IBot ibot_0)
			{
				return ibot_0.Name == string_0;
			}
		}

		[CompilerGenerated]
		private sealed class Class28
		{
			public string string_0;

			internal bool method_0(IRoutine iroutine_0)
			{
				return iroutine_0.Name == string_0;
			}
		}

		[CompilerGenerated]
		private sealed class Class29
		{
			public string string_0;

			internal bool method_0(IRoutine iroutine_0)
			{
				return iroutine_0.Name == string_0;
			}
		}

		[CompilerGenerated]
		private sealed class Class30
		{
			public BotChangedEventArgs botChangedEventArgs_0;

			public MainWindow mainWindow_0;

			internal void method_0()
			{
				mainWindow_0.comboBox_0.SelectedItem = botChangedEventArgs_0.New;
			}
		}

		[CompilerGenerated]
		private sealed class Class31
		{
			public RoutineChangedEventArgs routineChangedEventArgs_0;

			public MainWindow mainWindow_0;

			internal void method_0()
			{
				mainWindow_0.comboBox_1.SelectedItem = routineChangedEventArgs_0.New;
			}
		}

		[CompilerGenerated]
		private sealed class Class32
		{
			public IPlugin iplugin_0;

			internal bool method_0(IPlugin iplugin_1)
			{
				return iplugin_1 == iplugin_0;
			}
		}

		[CompilerGenerated]
		private sealed class Class33
		{
			public string string_0;

			public string string_1;

			public List<string> list_0;

			internal void method_0(object object_0)
			{
				smethod_1(string_0, string_1, list_0);
			}
		}

		[CompilerGenerated]
		private sealed class Class34
		{
			public string string_0;

			public string string_1;

			public List<string> list_0;

			internal void method_0(object object_0)
			{
				smethod_1(string_0, string_1, list_0);
			}
		}

		private static readonly ILog ilog_0 = Triton.Common.LogUtilities.Logger.GetLoggerInstanceForType();

		private bool bool_0 = true;

		private Mutex mutex_0;

		public static Process process_0;

		private DispatcherTimer dispatcherTimer_0;

		private DispatcherTimer dispatcherTimer_1;

		private readonly Stopwatch stopwatch_0 = new Stopwatch();//记录运行时间

		//internal Grid grid_0;

		//internal System.Windows.Controls.Button button_0;

		//internal System.Windows.Controls.ComboBox comboBox_0;

		//internal System.Windows.Controls.ComboBox comboBox_1;

		//internal System.Windows.Controls.Button button_1;

		//internal System.Windows.Controls.Button button_2;

		//internal Grid grid_1;

		//internal RowDefinition rowDefinition_0;

		//internal RowDefinition rowDefinition_1;

		//internal RowDefinition rowDefinition_2;

		//internal GridSplitter gridSplitter_0;

		//internal System.Windows.Controls.TextBox textBox_0;

		//internal System.Windows.Controls.Button button_3;

		//internal System.Windows.Controls.Button button_4;

		//internal System.Windows.Controls.Button button_5;

		//internal ScrollViewer scrollViewer_0;
		/*
		internal System.Windows.Controls.RichTextBox richTextBox_0;

		internal System.Windows.Controls.Primitives.StatusBar statusBar_0;

		internal System.Windows.Controls.Label label_0;

		internal System.Windows.Controls.Label label_1;

		internal System.Windows.Controls.TabControl tabControl_0;

		internal System.Windows.Controls.ListBox listBox_0;

		internal TextBlock textBlock_0;

		internal TextBlock textBlock_1;

		internal System.Windows.Controls.CheckBox checkBox_0;

		internal System.Windows.Controls.Button button_6;

		internal ScrollViewer scrollViewer_1;

		internal TextBlock textBlock_2;

		internal TabItem tabItem_0;

		internal System.Windows.Controls.TabControl tabControl_1;

		internal TabItem tabItem_1;

		internal TabItem tabItem_2;

		internal System.Windows.Controls.ComboBox comboBox_2;

		internal System.Windows.Controls.CheckBox checkBox_1;

		internal System.Windows.Controls.CheckBox checkBox_2;

		internal System.Windows.Controls.CheckBox checkBox_3;

		internal System.Windows.Controls.CheckBox checkBox_4;

		internal System.Windows.Controls.CheckBox checkBox_5;

		internal TabItem tabItem_3;

		internal System.Windows.Controls.TextBox textBox_1;

		internal System.Windows.Controls.TextBox textBox_2;

		internal System.Windows.Controls.TextBox textBox_3;

		internal System.Windows.Controls.Button button_7;

		internal System.Windows.Controls.Button button_8;

		internal System.Windows.Controls.TextBox textBox_4;

		internal System.Windows.Controls.Button button_9;

		internal TabItem tabItem_4;*/

		private bool bool_1;

		private string title = "炉石兄弟V7.2.0--[2022-11-05]--By琴弦上的宇宙+Bald9--仅供学习，免费使用！";

		private IPlugin IPlugin_0 => listBox_0.SelectedItem as IPlugin;

		protected override void OnSourceInitialized(EventArgs e)
		{
			try
			{
				base.OnSourceInitialized(e);
				(PresentationSource.FromVisual(this) as HwndSource).AddHook(method_0);
			}
			catch (Exception arg)
			{
				ilog_0.ErrorFormat("[OnSourceInitialized] {0}.", arg);
				throw;
			}
		}

		private IntPtr method_0(IntPtr intptr_0, int int_0, IntPtr intptr_1, IntPtr intptr_2, ref bool bool_2)
		{
			if (!MainSettings.Instance.AllowExternalAccess)
			{
				return IntPtr.Zero;
			}
			switch (int_0)
			{
			case 1024:
				bool_2 = true;
				if (MainSettings.Instance.AccessToken != 0)
				{
					return (IntPtr)1;
				}
				ilog_0.InfoFormat("[WndProc] The access token has been assigned.");
				MainSettings.Instance.AccessToken = intptr_2.ToInt32();
				return (IntPtr)0;
			case 1025:
				bool_2 = true;
				if (BotManager.IsRunning)
				{
					return (IntPtr)2;
				}
				if (intptr_2.ToInt32() != MainSettings.Instance.AccessToken)
				{
					return (IntPtr)1;
				}
				ilog_0.InfoFormat("[WndProc] An external close request has been processed. Now closing the program.");
				base.Dispatcher.Invoke(delegate
				{
					System.Windows.Application.Current.Shutdown();
				});
				return (IntPtr)0;
			case 1026:
				bool_2 = true;
				if (intptr_1.ToInt32() == 0)
				{
					if (!TritonHs.IsBotFullyLoaded)
					{
						return (IntPtr)0;
					}
					return (IntPtr)1;
				}
				if (intptr_1.ToInt32() == 1)
				{
					if (!BotManager.IsRunning)
					{
						return (IntPtr)0;
					}
					return (IntPtr)1;
				}
				if (intptr_1.ToInt32() == 2)
				{
					if (!BotManager.ClientFrozen)
					{
						return (IntPtr)0;
					}
					return (IntPtr)1;
				}
				if (intptr_1.ToInt32() == 3)
				{
					return (IntPtr)TritonHs.Memory.Process.Id;
				}
				break;
			}
			return IntPtr.Zero;
		}
		
		/// <summary> </summary>
		public MainWindow()
		{

			InitializeComponent();
			Triton.Common.LogUtilities.Logger.AddWpfListener(scrollViewer_0, richTextBox_0);
		}

		private void MainWindowLoad(object sender, RoutedEventArgs e)
		{
			try
			{
				base.Title = title;
				SetBinding(Window.LeftProperty, new System.Windows.Data.Binding("WindowX")
				{
					Source = MainSettings.Instance,
					Mode = BindingMode.TwoWay
				});
				SetBinding(Window.TopProperty, new System.Windows.Data.Binding("WindowY")
				{
					Source = MainSettings.Instance,
					Mode = BindingMode.TwoWay
				});
				SetBinding(FrameworkElement.WidthProperty, new System.Windows.Data.Binding("WindowWidth")
				{
					Source = MainSettings.Instance,
					Mode = BindingMode.TwoWay
				});
				SetBinding(FrameworkElement.HeightProperty, new System.Windows.Data.Binding("WindowHeight")
				{
					Source = MainSettings.Instance,
					Mode = BindingMode.TwoWay
				});
				MainSettings.Instance.LoadRowDefinitions(rowDefinition_0, rowDefinition_1, rowDefinition_2);
				InitAllModule();
				textBox_0.Text = Triton.Common.LogUtilities.Logger.FileName;
				method_17();
				method_18();
				method_19();
				method_20();
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred.", exception);
			}
		}
		/// <summary>
		/// 添加标签页
		/// </summary>
		/// <param name="object_0"></param>
		private void method_2(object object_0)
		{
			IConfigurable configurable = object_0 as IConfigurable;
			IAuthored authored = object_0 as IAuthored;
			if (configurable != null && authored != null)
			{
				System.Windows.Controls.UserControl control = configurable.Control;
				if (control != null)
				{
					TabItem newItem;
					newItem = new TabItem
					{
						Header = authored.Name,
						Content = control,
						Tag = object_0
					};
					tabControl_1.Items.Add(newItem);
				}
			}
		}
		/// <summary>
		/// 判断Memory是否绑定到炉石
		/// </summary>
		public static bool HasAttachMemory = false;
        /// <summary>
        /// 绑定炉石
        /// </summary>
        /// 
        public void CloseWindow(object sender, EventArgs e)
        {
            System.Environment.Exit(0);
        }
        public void InitHSAttach() 
		{
            System.Windows.Forms.Timer TimerClose =
				new System.Windows.Forms.Timer();
            TimerClose.Interval = 10000;
            TimerClose.Tick += CloseWindow;
            if (process_0 != null && HasAttachMemory)
			{
				return;
			}
			base.Dispatcher.Invoke(delegate
			{
				if (!Class9.smethod_4(out mutex_0, out process_0))//获取炉石进程
				{
                    TimerClose.Start();
                    ilog_0.Error("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.");
					System.Windows.MessageBox.Show(string.Format("请先打开炉石程序，再打开本程序", Environment.NewLine), "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
					System.Environment.Exit(0);
				}
				else
				{
					dispatcherTimer_0 = new DispatcherTimer(TimeSpan.FromSeconds(1.0), DispatcherPriority.Normal, method_9, base.Dispatcher);
					dispatcherTimer_0.Start();
					ilog_0.Info("检测到炉石进程！");

				}
			});
			string string_;
			if (process_0 == null)
			{
				//base.Dispatcher.BeginInvoke(new Action(base.Close));
				//ilog_0.Error("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.");
				ilog_0.Warn("未能检测到炉石进程，请启动炉石！");
				//System.Windows.MessageBox.Show("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.");
				//System.Windows.MessageBox.Show("未能检测到炉石进程，请启动炉石！", "Warn", MessageBoxButton.OK, MessageBoxImage.Hand);
			}
			else if (!(HasAttachMemory = TritonHs.smethod_0(process_0, Class12.smethod_4, out string_)))//绑定到炉石
			{
				TimerClose.Start();
				//ilog_0.Error(string_);
				ilog_0.Warn(string_);
				ilog_0.Warn("未能绑定到炉石进程，请重新启动炉石！");
				System.Windows.MessageBox.Show("未能绑定到炉石进程，请重新启动炉石！");
				System.Environment.Exit(0);
				//System.Windows.MessageBox.Show(string_, "Warn", MessageBoxButton.OK, MessageBoxImage.Hand);
				//base.Dispatcher.BeginInvoke(new Action(base.Close));


			}
			else 
			{
				TritonHs.Memory.ProcessExited += delegate
				{
					ilog_0.Info("[ProcessExited] The game process has closed. Hearthbuddy will now close.");
					Class12.smethod_0();
					Environment.Exit(0);
				};
				TritonHs.Memory.Executor.FrameDropWaitTime = 15000u;
				TritonHs.Memory.Executor.ExecuteWaitTime = 15000;
				TritonHs.Memory.DisableCache();
				TritonHs.Memory.ClearCache();
				ilog_0.Info("绑定到炉石进程！");
				using (TritonHs.AcquireFrame())
                {
                    
                }
			}
		}
		/// <summary>
		/// 初始化，绑定炉石，bot和策略
		/// </summary>
		private void InitAllModule()
		{
			ThreadPool.QueueUserWorkItem(delegate
			{
				try
				{
					InitHSAttach();
					//else
					{
						/*
						TritonHs.Memory.ProcessExited += delegate
						{
							ilog_0.Info("[ProcessExited] The game process has closed. Hearthbuddy will now close.");
							Class12.smethod_0();
							Environment.Exit(0);
						};
						TritonHs.Memory.Executor.FrameDropWaitTime = 15000u;
						TritonHs.Memory.Executor.ExecuteWaitTime = 15000;
						TritonHs.Memory.DisableCache();
						TritonHs.Memory.ClearCache();
						*/
						//using (TritonHs.AcquireFrame())
						//{
						//	version = Triton.Game.Mapping.Version.version;
						//	clientChangelist = Triton.Game.Mapping.Version.clientChangelist;
						//}
						//if (version != Class247.UInt32_1 && clientChangelist != Class247.UInt32_2)
						{
							//ilog_0.InfoFormat("Hearthstone client version ({0}, {1})", version, clientChangelist);
							new Coroutine(() => smethod_0());
							Configuration.Instance.AddSettings(MainSettings.Instance);
							Configuration.Instance.AddSettings(DevSettings.Instance);
							Configuration.Instance.SaveAll();
							base.Dispatcher.Invoke(delegate
							{
								tabItem_0.DataContext = GlobalSettings.Instance;
							});
							BotManager.PreStart += method_11;
							BotManager.PostStop += method_10;
							BotManager.Load();
							base.Dispatcher.Invoke(delegate
							{
								foreach (IBot bot3 in BotManager.Bots)
								{
									method_2(bot3);
								}
							});
							comboBox_0.Dispatcher.BeginInvoke((Action)delegate
							{
								List<IBot> bots = BotManager.Bots;
								comboBox_0.ItemsSource = bots;
								if (CommandLine.Arguments.Exists("bot"))
								{
									string string_5 = CommandLine.Arguments.Single("bot");
									IBot bot = bots.FirstOrDefault((IBot ibot_0) => ibot_0.Name == string_5);
									if (bot != null)
									{
										comboBox_0.SelectedItem = bot;
									}
								}
								else if (!string.IsNullOrEmpty(MainSettings.Instance.LastBot))
								{
									string string_4 = MainSettings.Instance.LastBot;
									IBot bot2 = bots.FirstOrDefault((IBot ibot_0) => ibot_0.Name == string_4);
									if (bot2 != null)
									{
										comboBox_0.SelectedItem = bot2;
									}
								}
								if (comboBox_0.SelectedItem == null)
								{
									comboBox_0.SelectedItem = bots.FirstOrDefault();
								}
								method_14();
							});
							BotManager.OnBotChanged += method_6;
							RoutineManager.Load();
							base.Dispatcher.Invoke(delegate
							{
								foreach (IRoutine routine3 in RoutineManager.Routines)
								{
									method_2(routine3);
								}
							});
							comboBox_1.Dispatcher.BeginInvoke((Action)delegate
							{
								List<IRoutine> routines = RoutineManager.Routines;
								comboBox_1.ItemsSource = routines;
								if (CommandLine.Arguments.Exists("routine"))
								{
									string string_3 = CommandLine.Arguments.Single("routine");
									IRoutine routine = routines.FirstOrDefault((IRoutine iroutine_0) => iroutine_0.Name == string_3);
									if (routine != null)
									{
										comboBox_1.SelectedItem = routine;
									}
								}
								else if (!string.IsNullOrEmpty(MainSettings.Instance.LastRoutine))
								{
									string string_2 = MainSettings.Instance.LastRoutine;
									IRoutine routine2 = routines.FirstOrDefault((IRoutine iroutine_0) => iroutine_0.Name == string_2);
									if (routine2 != null)
									{
										comboBox_1.SelectedItem = routine2;
									}
								}
								if (comboBox_1.SelectedItem == null)
								{
									comboBox_1.SelectedItem = routines.FirstOrDefault();
								}
								method_14();
							});
							RoutineManager.OnRoutineChanged += method_7;

							PluginManager.Load();
							foreach (IPlugin plugin in PluginManager.Plugins)
							{
                                if (MainSettings.Instance.EnabledPlugins.Contains(plugin.Name))
                                {
                                    using (TritonHs.AcquireFrame())
                                    {
										PluginManager.Enable(plugin);
										//PluginManager.Disable(plugin);
									}
                                    Thread.Sleep(20);
                                }
                                else
                                {
                                    using (TritonHs.AcquireFrame())
                                    {
                                        PluginManager.Disable(plugin);
                                    }
                                    Thread.Sleep(20);
                                }
                            }
							listBox_0.Dispatcher.Invoke(() => listBox_0.ItemsSource = PluginManager.Plugins, DispatcherPriority.Normal);
							base.Dispatcher.Invoke(delegate
							{
                                foreach (IPlugin plugin2 in PluginManager.Plugins)
                                {
									if (listBox_0.SelectedItem==null)
									{
										listBox_0.SelectedItem = plugin2;
										textBlock_0.Text = plugin2.Author;
										textBlock_1.Text = plugin2.Version;
										textBlock_2.Text = plugin2.Description;
										checkBox_0.IsEnabled = true;
										checkBox_0.IsChecked = plugin2.IsEnabled;
										button_6.IsEnabled = true;
									}
									method_2(plugin2);
                                }
                                method_14();
							});
							PluginManager.PluginEnabled += method_5;
							PluginManager.PluginDisabled += method_4;
							ilog_0.ErrorFormat(title);
							base.Dispatcher.Invoke(delegate
							{
								startButton.IsEnabled = true;
								comboBox_0.IsEnabled = true;
								comboBox_1.IsEnabled = true;
								button_1.IsEnabled = true;
								button_2.IsEnabled = true;
							});
							base.Dispatcher.Invoke(delegate
							{
								dispatcherTimer_1 = new DispatcherTimer(TimeSpan.FromMilliseconds(1000.0), DispatcherPriority.Normal, method_8, base.Dispatcher);
								dispatcherTimer_1.Start();
							});
							stopwatch_0.Restart();
							RoutineManager.OnRoutineChanged += method_7;
							BotManager.OnBotChanged += method_6;

							TritonHs.IsBotFullyLoaded = true;
							Hotkeys.Register("BotManager.StartStop", Keys.S, ModifierKeys.Alt | ModifierKeys.Shift, delegate
							{
								if (BotManager.IsRunning)
								{
									BotManager.Stop();
								}
								else
								{
									BotManager.Start();
								}
							});
							if (CommandLine.Arguments.Exists("autostart"))
							{
								if (process_0 != null && HasAttachMemory)
								{
									BotManager.Start();
								}
							}
						}
						//else
						//{
						//	string string_;
						//	string_ = $"This client version ({version}, {clientChangelist}) is unsupported. Hearthbuddy currently supports client version ({Class247.UInt32_1}, {Class247.UInt32_2}). Please check the forums for more information: https://www.thebuddyforum.com/hearthbuddy-forum/";
						//	ilog_0.ErrorFormat(string_);
						//	System.Windows.MessageBox.Show(string_, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
						//	base.Dispatcher.BeginInvoke(new Action(base.Close));
						//}
					}
				}
				catch (Exception exception)
				{
					ilog_0.Error("炉石兄弟启动失败，请重启炉石兄弟.（建议等炉石客户端完全启动后再启动炉石兄弟，即中控里面的时间设置长一点.“炉石启动30秒后，开始启动兄弟”，把30改成60试试.）");
				}
			});
		}

		private void method_4(IPlugin iplugin_0)
		{
			base.Dispatcher.BeginInvoke(new Action(method_14));
		}

		private void method_5(IPlugin iplugin_0)
		{
			base.Dispatcher.BeginInvoke(new Action(method_14));
		}

		private void method_6(object sender, BotChangedEventArgs e)
		{
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				comboBox_0.SelectedItem = e.New;
			});
		}

		private void method_7(object sender, RoutineChangedEventArgs e)
		{
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				comboBox_1.SelectedItem = e.New;
			});
		}

		private void checkBox_0_Unchecked(object sender, RoutedEventArgs e)
		{
			try
			{
				if (BotManager.IsRunning)
				{
					System.Windows.MessageBox.Show("Please Stop the current bot before trying to enable plugins.", "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
					return;
				}
				IPlugin iPlugin_ = IPlugin_0;
				if (iPlugin_ == null)
				{
					System.Windows.MessageBox.Show("Please highlight the plugin you wish to enable or disable first, before clicking the checkbox.", "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
					return;
				}
				using (TritonHs.AcquireFrame())
				{
					PluginManager.Disable(iPlugin_);
				}
				MainSettings.Instance.EnabledPlugins = PluginManager.EnabledPlugins.Select((IPlugin iplugin_0) => iplugin_0.Name).ToList();
				Configuration.Instance.SaveAll();
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void checkBox_0_Checked(object sender, RoutedEventArgs e)
		{
			try
			{
				if (BotManager.IsRunning)
				{
					System.Windows.MessageBox.Show("Please Stop the current bot before trying to disable plugins.", "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
					return;
				}
				IPlugin iPlugin_ = IPlugin_0;
				if (iPlugin_ == null)
				{
					System.Windows.MessageBox.Show("Please highlight the plugin you wish to enable or disable first, before clicking the checkbox.", "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
					return;
				}
				using (TritonHs.AcquireFrame())
				{
					PluginManager.Enable(iPlugin_);
				}
				MainSettings.Instance.EnabledPlugins = PluginManager.EnabledPlugins.Select((IPlugin iplugin_0) => iplugin_0.Name).ToList();
				Configuration.Instance.SaveAll();
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void listBox_0_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			try
			{
				IPlugin iPlugin_ = IPlugin_0;
				if (iPlugin_ == null)
				{
					checkBox_0.IsChecked = false;
					checkBox_0.IsEnabled = false;
					button_6.IsEnabled = false;
					return;
				}
				textBlock_0.Text = iPlugin_.Author;
				textBlock_1.Text = iPlugin_.Version;
				textBlock_2.Text = iPlugin_.Description;
				checkBox_0.IsEnabled = true;
				checkBox_0.IsChecked = iPlugin_.IsEnabled;
				button_6.IsEnabled = true;
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void method_8(object sender, EventArgs e)
		{
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				try
				{
					TritonHs.GuiTick(this);
				}
				catch (Exception exception)
				{
					ilog_0.Debug("[Ui] An exception was caught in BotGuiTimer:", exception);
				}
			});
		}

		private void method_9(object sender, EventArgs e)
		{
			if (stopwatch_0.IsRunning && stopwatch_0.ElapsedMilliseconds >= 3000L)
			{
				startButton.IsEnabled = true;
				bool flag = !BotManager.IsRunning;
				comboBox_1.IsEnabled = flag;
				comboBox_0.IsEnabled = flag;
				listBox_0.IsEnabled = flag;
				checkBox_0.IsEnabled = flag;
				startButton.Content = ((!flag) ? "停止运行（学习链接 https://gitee.com/UniverseString）" : "开始运行（学习链接 https://gitee.com/UniverseString）");
			}
		}

		private static async Task smethod_0()
		{
		}

		private void method_10(IBot ibot_0)
		{
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				stopwatch_0.Restart();
			});
			if (bool_0)
			{
				base.Dispatcher.BeginInvoke((Action)delegate
				{
					startButton.IsEnabled = false;
					comboBox_1.IsEnabled = false;
					comboBox_0.IsEnabled = false;
					checkBox_0.IsEnabled = false;
					listBox_0.IsEnabled = false;
				});
			}
		}

		private void method_11(IBot ibot_0)
		{
			base.Dispatcher.BeginInvoke((Action)delegate
			{
				stopwatch_0.Restart();
			});
			if (bool_0)
			{
				base.Dispatcher.BeginInvoke((Action)delegate
				{
					startButton.IsEnabled = false;
					comboBox_1.IsEnabled = false;
					comboBox_0.IsEnabled = false;
					checkBox_0.IsEnabled = false;
					listBox_0.IsEnabled = false;
				});
			}
		}

		private void MainWindowClosing(object sender, CancelEventArgs e)
		{
			try
			{
				if (BotManager.IsRunning)
				{
					ilog_0.ErrorFormat("Please wait for the current bot to stop before closing the program.");
					e.Cancel = true;
				}
				else if (!startButton.IsEnabled)
				{
					if (TritonHs.IsBotFullyLoaded)
					{
						ilog_0.ErrorFormat("Please wait for the current bot to stop before closing the program.");
						TritonHs.AcquireFrame().Dispose();
						e.Cancel = true;
					}
				}
				else
				{
					TritonHs.bool_0 = true;
				}
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void MainWindowClosed(object sender, EventArgs e)
		{
			Class12.smethod_0();
			MainSettings.Instance.SaveRowDefinitions(rowDefinition_0, rowDefinition_1, rowDefinition_2);
			PluginManager.Deinitialize();
			RoutineManager.Deinitialize();
			BotManager.Deinitialize();
			Configuration.Instance.SaveAll();
			foreach (Window window in System.Windows.Application.Current.Windows)
			{
				if (window.IsVisible)
				{
					window.Close();
				}
			}
			if (mutex_0 != null)
			{
				mutex_0.Dispose();
				mutex_0 = null;
			}
			if (process_0 != null)
			{
				process_0.Dispose();
				process_0 = null;
			}
		}
		/// <summary>
		/// 主页面开始按钮点击事件
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void StartButton_Click(object sender, RoutedEventArgs e)
		{
			Configuration.Instance.SaveAll();
			InitHSAttach();
			if (process_0 == null)
			{
				System.Windows.MessageBox.Show("未能检测到炉石进程，请启动炉石！");
			}
			else if (!HasAttachMemory)
			{
				System.Windows.MessageBox.Show("未能绑定到炉石进程，请重新启动炉石！");
			}
			startButton.IsEnabled = false;
			comboBox_1.IsEnabled = false;
			comboBox_0.IsEnabled = false;
			checkBox_0.IsEnabled = false;
			listBox_0.IsEnabled = false;
			try
			{
				bool_0 = false;
				if (BotManager.IsRunning)
				{
					BotManager.Stop();
				}
				else
				{
					//HearthstoneApplication.s_mode = ApplicationMode.INTERNAL;
					BotManager.Start();//开始bot脚本
				}
			}
			finally
			{
				bool_0 = true;
			}
			stopwatch_0.Restart();
		}

		private void comboBox_0_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			try
			{
				IBot bot2 = (BotManager.CurrentBot = comboBox_0.SelectedItem as IBot);
				if (bot2 != null)
				{
					MainSettings.Instance.LastBot = bot2.Name;
				}
				ilog_0.DebugFormat("Current bot set to {0}.", (bot2 != null) ? bot2.Name : "(null)");
				//Configuration.Instance.SaveAll();
				method_14();
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void comboBox_1_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			try
			{
				IRoutine routine2 = (RoutineManager.CurrentRoutine = comboBox_1.SelectedItem as IRoutine);
				if (routine2 != null)
				{
					MainSettings.Instance.LastRoutine = routine2.Name;
				}
				ilog_0.DebugFormat("Current routine set to {0}.", (routine2 != null) ? routine2.Name : "(null)");
				//Configuration.Instance.SaveAll();
				method_14();
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void method_14()
		{
			foreach (TabItem item in (IEnumerable)tabControl_1.Items)
			{
				IBot bot = item.Tag as IBot;
				if (bot != null)
				{
					item.Visibility = ((comboBox_0.SelectedItem != bot) ? Visibility.Collapsed : Visibility.Visible);
				}
				IRoutine routine = item.Tag as IRoutine;
				if (routine != null)
				{
					item.Visibility = ((comboBox_1.SelectedItem != routine) ? Visibility.Collapsed : Visibility.Visible);
				}
				IPlugin iplugin_2 = item.Tag as IPlugin;
				if (iplugin_2 != null)
				{
					IPlugin plugin = PluginManager.Plugins.First((IPlugin iplugin_1) => iplugin_1 == iplugin_2);
					item.Visibility = ((!plugin.IsEnabled) ? Visibility.Collapsed : Visibility.Visible);
				}
			}
			TabItem tabItem2 = tabControl_1.SelectedItem as TabItem;
			if (tabItem2 != null && tabItem2.Visibility == Visibility.Collapsed)
			{
				tabControl_1.SelectedIndex = 0;
			}
		}

		private void button_5_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				Triton.Common.LogUtilities.Logger.Clear();
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void button_3_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				System.Windows.Clipboard.SetText(Triton.Common.LogUtilities.Logger.FileName);
				ilog_0.DebugFormat("The log filename has been copied to the clipboard: {0}", Triton.Common.LogUtilities.Logger.FileName.Replace(Environment.UserName, "<Username>"));
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void button_4_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				string text = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
				Directory.CreateDirectory(text);
				File.Copy(Triton.Common.LogUtilities.Logger.FileName, Path.Combine(text, Path.GetFileName(Triton.Common.LogUtilities.Logger.FileName)));
				string text2 = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName().Replace(".", "")) + ".zip";
				ZipFile.CreateFromDirectory(text, text2);
				System.Windows.Clipboard.SetText(text2);
				ilog_0.DebugFormat("The log file has been zipped and the full filename has been copied to the clipboard: {0}", text2.Replace(Environment.UserName, "<Username>"));
			}
			catch (Exception exception)
			{
				ilog_0.Debug("The log file could not be compressed. You will have to manually compress it.", exception);
			}
		}

		private void button_7_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				string string_0 = textBox_3.Text;
				if (string.IsNullOrEmpty(string_0))
				{
					return;
				}
				string string_1 = textBox_1.Text;
				if (!string.IsNullOrEmpty(string_1))
				{
					List<string> list_0 = textBox_4.Text.Split(new char[3] { '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList();
					Configuration.Instance.SaveAll();
					ThreadPool.QueueUserWorkItem(delegate
					{
						smethod_1(string_0, string_1, list_0);
					});
				}
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void button_8_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				string string_0 = textBox_3.Text;
				string string_1;
				try
				{
					string_1 = File.ReadAllText(textBox_2.Text);
				}
				catch (Exception message)
				{
					ilog_0.Error(message);
					return;
				}
				List<string> list_0 = textBox_4.Text.Split(new char[3] { '\r', '\n', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToList();
				if (!string.IsNullOrEmpty(string_0) && !string.IsNullOrEmpty(string_1))
				{
					Configuration.Instance.SaveAll();
					ThreadPool.QueueUserWorkItem(delegate
					{
						smethod_1(string_0, string_1, list_0);
					});
				}
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void button_9_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
				bool? flag = openFileDialog.ShowDialog();
				if (flag.HasValue && flag.Value)
				{
					DevSettings.Instance.FileName = openFileDialog.FileName;
				}
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private static void smethod_1(string string_0, string string_1, IEnumerable<string> ienumerable_0)
		{
			try
			{
				using CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider();
				CompilerParameters compilerParameters = new CompilerParameters
				{
					GenerateExecutable = false,
					GenerateInMemory = true
				};
				foreach (string item in ienumerable_0)
				{
					compilerParameters.ReferencedAssemblies.Add(item);
				}
				CompilerResults compilerResults = cSharpCodeProvider.CompileAssemblyFromSource(compilerParameters, string_1);
				if (compilerResults.Errors.Count > 0)
				{
					StringBuilder stringBuilder = new StringBuilder();
					foreach (CompilerError error in compilerResults.Errors)
					{
						stringBuilder.AppendFormat("Line number " + error.Line + ", Error Number: " + error.ErrorNumber + ", '" + error.ErrorText + ";");
						stringBuilder.AppendLine();
					}
					throw new Exception(stringBuilder.ToString());
				}
				Type type = compilerResults.CompiledAssembly.GetType(string_0);
				object obj = Activator.CreateInstance(type);
				object obj2 = type.GetMethod("Execute").Invoke(obj, new object[0]);
				if (obj2 != null)
				{
					ilog_0.Info(obj2);
				}
			}
			catch (Exception exception)
			{
				ilog_0.Error("[Ui] An exception occurred:", exception);
			}
		}

		private void method_15()
		{
			foreach (TabItem item in (IEnumerable)tabControl_0.Items)
			{
				if (item.Header.ToString().Equals("脚本配置", StringComparison.InvariantCulture))
				{
					tabControl_0.SelectedItem = item;
					break;
				}
			}
		}

		private void method_16(object object_0)
		{
			IConfigurable obj = object_0 as IConfigurable;
			IAuthored authored = object_0 as IAuthored;
			bool flag = false;
			if (obj != null && authored != null)
			{
				foreach (TabItem item in (IEnumerable)tabControl_1.Items)
				{
					if (item.Header.ToString().Equals(authored.Name, StringComparison.InvariantCulture))
					{
						tabControl_1.SelectedItem = item;
						flag = true;
						break;
					}
				}
			}
			if (flag)
			{
				return;
			}
			foreach (TabItem item2 in (IEnumerable)tabControl_1.Items)
			{
				if (item2.Header.ToString().Equals("兄弟配置", StringComparison.InvariantCulture))
				{
					tabControl_1.SelectedItem = item2;
					break;
				}
			}
		}

		private void button_6_Click(object sender, RoutedEventArgs e)
		{
			IPlugin iPlugin_ = IPlugin_0;
			if (iPlugin_ != null)
			{
				if (iPlugin_.IsEnabled)
				{
					method_15();
					method_16(iPlugin_);
				}
				else
				{
					ilog_0.InfoFormat("[PluginSettings_Click] The plugin must be enabled first.");
				}
			}
		}

		private void button_1_Click(object sender, RoutedEventArgs e)
		{
			method_15();
			method_16(BotManager.CurrentBot);
		}

		private void button_2_Click(object sender, RoutedEventArgs e)
		{
			method_15();
			method_16(RoutineManager.CurrentRoutine);
		}

		private void method_17()
		{
			if (tabItem_3 != null)
			{
				if (MainSettings.Instance.ShowDevTab)
				{
					tabItem_3.Visibility = Visibility.Visible;
				}
				else
				{
					tabItem_3.Visibility = Visibility.Collapsed;
				}
			}
		}

		private void method_18()
		{
			if (tabItem_4 != null)
			{
				if (MainSettings.Instance.ShowToolsTab)
				{
					tabItem_4.Visibility = Visibility.Visible;
				}
				else
				{
					tabItem_4.Visibility = Visibility.Collapsed;
				}
			}
		}

		private void method_19()
		{
			if (tabItem_1 != null)
			{
				if (MainSettings.Instance.ShowConfigurationTab)
				{
					tabItem_1.Visibility = Visibility.Visible;
				}
				else
				{
					tabItem_1.Visibility = Visibility.Collapsed;
				}
			}
		}

		private void method_20()
		{
			if (tabItem_2 != null)
			{
				if (MainSettings.Instance.ShowGlobalTab)
				{
					tabItem_2.Visibility = Visibility.Visible;
				}
				else
				{
					tabItem_2.Visibility = Visibility.Collapsed;
				}
			}
		}

		private void checkBox_1_Checked(object sender, RoutedEventArgs e)
		{
			method_17();
		}

		private void checkBox_1_Unchecked(object sender, RoutedEventArgs e)
		{
			method_17();
		}

		private void checkBox_2_Checked(object sender, RoutedEventArgs e)
		{
			method_18();
		}

		private void checkBox_2_Unchecked(object sender, RoutedEventArgs e)
		{
			method_18();
		}

		private void checkBox_3_Checked(object sender, RoutedEventArgs e)
		{
			method_19();
		}

		private void checkBox_3_Unchecked(object sender, RoutedEventArgs e)
		{
			method_19();
		}

		private void checkBox_4_Checked(object sender, RoutedEventArgs e)
		{
			method_20();
		}

		private void checkBox_4_Unchecked(object sender, RoutedEventArgs e)
		{
			method_20();
		}

		private void comboBox_2_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			if (TritonHs.IsBotFullyLoaded)
			{
				ilog_0.WarnFormat("[SettingsWindow] Please restart the bot for the changes to take effect.");
			}
		}
		/*
		/// <summary>
		/// InitializeComponent
		/// </summary>
		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		public void InitializeComponent()
		{
			if (!bool_1)
			{
				bool_1 = true;
				Uri resourceLocator = new Uri("/Hearthbuddy;component/windows/mainwindow.xaml", UriKind.Relative);
				System.Windows.Application.LoadComponent(this, resourceLocator);
			}
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		[EditorBrowsable(EditorBrowsableState.Never)]
		void IComponentConnector.Connect(int connectionId, object target)
		{
			switch (connectionId)
			{
			default:
				bool_1 = true;
				break;
			case 1:
				((MainWindow)target).Closed += method_13;
				((MainWindow)target).Loaded += method_1;
				((MainWindow)target).Closing += method_12;
				break;
			case 2:
				grid_0 = (Grid)target;
				break;
			case 3:
				button_0 = (System.Windows.Controls.Button)target;
				button_0.Click += button_0_Click;
				break;
			case 4:
				comboBox_0 = (System.Windows.Controls.ComboBox)target;
				comboBox_0.SelectionChanged += comboBox_0_SelectionChanged;
				break;
			case 5:
				comboBox_1 = (System.Windows.Controls.ComboBox)target;
				comboBox_1.SelectionChanged += comboBox_1_SelectionChanged;
				break;
			case 6:
				button_1 = (System.Windows.Controls.Button)target;
				button_1.Click += button_1_Click;
				break;
			case 7:
				button_2 = (System.Windows.Controls.Button)target;
				button_2.Click += button_2_Click;
				break;
			case 8:
				grid_1 = (Grid)target;
				break;
			case 9:
				rowDefinition_0 = (RowDefinition)target;
				break;
			case 10:
				rowDefinition_1 = (RowDefinition)target;
				break;
			case 11:
				rowDefinition_2 = (RowDefinition)target;
				break;
			case 12:
				gridSplitter_0 = (GridSplitter)target;
				break;
			case 13:
				textBox_0 = (System.Windows.Controls.TextBox)target;
				break;
			case 14:
				button_3 = (System.Windows.Controls.Button)target;
				button_3.Click += button_3_Click;
				break;
			case 15:
				button_4 = (System.Windows.Controls.Button)target;
				button_4.Click += button_4_Click;
				break;
			case 16:
				button_5 = (System.Windows.Controls.Button)target;
				button_5.Click += button_5_Click;
				break;
			case 17:
				scrollViewer_0 = (ScrollViewer)target;
				break;
			case 18:
				richTextBox_0 = (System.Windows.Controls.RichTextBox)target;
				break;
			case 19:
				statusBar_0 = (System.Windows.Controls.Primitives.StatusBar)target;
				break;
			case 20:
				label_0 = (System.Windows.Controls.Label)target;
				break;
			case 21:
				label_1 = (System.Windows.Controls.Label)target;
				break;
			case 22:
				tabControl_0 = (System.Windows.Controls.TabControl)target;
				break;
			case 23:
				listBox_0 = (System.Windows.Controls.ListBox)target;
				listBox_0.SelectionChanged += listBox_0_SelectionChanged;
				break;
			case 24:
				textBlock_0 = (TextBlock)target;
				break;
			case 25:
				textBlock_1 = (TextBlock)target;
				break;
			case 26:
				checkBox_0 = (System.Windows.Controls.CheckBox)target;
				checkBox_0.Checked += checkBox_0_Checked;
				checkBox_0.Unchecked += checkBox_0_Unchecked;
				break;
			case 27:
				button_6 = (System.Windows.Controls.Button)target;
				button_6.Click += button_6_Click;
				break;
			case 28:
				scrollViewer_1 = (ScrollViewer)target;
				break;
			case 29:
				textBlock_2 = (TextBlock)target;
				break;
			case 30:
				tabItem_0 = (TabItem)target;
				break;
			case 31:
				tabControl_1 = (System.Windows.Controls.TabControl)target;
				break;
			case 32:
				tabItem_1 = (TabItem)target;
				break;
			case 33:
				tabItem_2 = (TabItem)target;
				break;
			case 34:
				comboBox_2 = (System.Windows.Controls.ComboBox)target;
				comboBox_2.SelectionChanged += comboBox_2_SelectionChanged;
				break;
			case 35:
				checkBox_1 = (System.Windows.Controls.CheckBox)target;
				checkBox_1.Checked += checkBox_1_Checked;
				checkBox_1.Unchecked += checkBox_1_Unchecked;
				break;
			case 36:
				checkBox_2 = (System.Windows.Controls.CheckBox)target;
				checkBox_2.Checked += checkBox_2_Checked;
				checkBox_2.Unchecked += checkBox_2_Unchecked;
				break;
			case 37:
				checkBox_3 = (System.Windows.Controls.CheckBox)target;
				checkBox_3.Checked += checkBox_3_Checked;
				checkBox_3.Unchecked += checkBox_3_Unchecked;
				break;
			case 38:
				checkBox_4 = (System.Windows.Controls.CheckBox)target;
				checkBox_4.Checked += checkBox_4_Checked;
				checkBox_4.Unchecked += checkBox_4_Unchecked;
				break;
			case 39:
				checkBox_5 = (System.Windows.Controls.CheckBox)target;
				break;
			case 40:
				tabItem_3 = (TabItem)target;
				break;
			case 41:
				textBox_1 = (System.Windows.Controls.TextBox)target;
				break;
			case 42:
				textBox_2 = (System.Windows.Controls.TextBox)target;
				break;
			case 43:
				textBox_3 = (System.Windows.Controls.TextBox)target;
				break;
			case 44:
				button_7 = (System.Windows.Controls.Button)target;
				button_7.Click += button_7_Click;
				break;
			case 45:
				button_8 = (System.Windows.Controls.Button)target;
				button_8.Click += button_8_Click;
				break;
			case 46:
				textBox_4 = (System.Windows.Controls.TextBox)target;
				break;
			case 47:
				button_9 = (System.Windows.Controls.Button)target;
				button_9.Click += button_9_Click;
				break;
			case 48:
				tabItem_4 = (TabItem)target;
				break;
			}
		}*/

		[CompilerGenerated]
		private void method_21(object object_0)
		{
			try
			{
				base.Dispatcher.Invoke(delegate
				{
					if (!Class9.smethod_4(out mutex_0, out process_0))
					{
						ilog_0.Error("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.");
						System.Windows.MessageBox.Show(string.Format("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.{0}{0}Hearthbuddy will now close.", Environment.NewLine), "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
					}
					else
					{
						dispatcherTimer_0 = new DispatcherTimer(TimeSpan.FromSeconds(1.0), DispatcherPriority.Normal, method_9, base.Dispatcher);
						dispatcherTimer_0.Start();
					}
				});
				if (process_0 == null)
				{
					base.Dispatcher.BeginInvoke(new Action(base.Close));
					return;
				}
				if (!TritonHs.smethod_0(process_0, Class12.smethod_4, out var string_))
				{
					ilog_0.Error(string_);
					System.Windows.MessageBox.Show(string_, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
					base.Dispatcher.BeginInvoke(new Action(base.Close));
					return;
				}
				TritonHs.Memory.ProcessExited += delegate
				{
					ilog_0.Info("[ProcessExited] The game process has closed. Hearthbuddy will now close.");
					Class12.smethod_0();
					Environment.Exit(0);
				};
				TritonHs.Memory.Executor.FrameDropWaitTime = 15000u;
				TritonHs.Memory.Executor.ExecuteWaitTime = 15000;
				TritonHs.Memory.DisableCache();
				TritonHs.Memory.ClearCache();
				int version;
				int clientChangelist;
				using (TritonHs.AcquireFrame())
				{
					version = Triton.Game.Mapping.Version.version;
					clientChangelist = Triton.Game.Mapping.Version.clientChangelist;
				}
				if (version != Class247.UInt32_1 && clientChangelist != Class247.UInt32_2)
				{
					ilog_0.InfoFormat("Hearthstone client version ({0}, {1})", version, clientChangelist);
					new Coroutine(() => smethod_0());
					Configuration.Instance.AddSettings(MainSettings.Instance);
					Configuration.Instance.AddSettings(DevSettings.Instance);
					Configuration.Instance.SaveAll();
					base.Dispatcher.Invoke(delegate
					{
						tabItem_0.DataContext = GlobalSettings.Instance;
					});
					BotManager.PreStart += method_11;
					BotManager.PostStop += method_10;
					BotManager.Load();
					base.Dispatcher.Invoke(delegate
					{
						foreach (IBot bot3 in BotManager.Bots)
						{
							method_2(bot3);
						}
					});
					comboBox_0.Dispatcher.BeginInvoke((Action)delegate
					{
						List<IBot> bots = BotManager.Bots;
						comboBox_0.ItemsSource = bots;
						if (CommandLine.Arguments.Exists("bot"))
						{
							string string_5 = CommandLine.Arguments.Single("bot");
							IBot bot = bots.FirstOrDefault((IBot ibot_0) => ibot_0.Name == string_5);
							if (bot != null)
							{
								comboBox_0.SelectedItem = bot;
							}
						}
						else if (!string.IsNullOrEmpty(MainSettings.Instance.LastBot))
						{
							string string_4 = MainSettings.Instance.LastBot;
							IBot bot2 = bots.FirstOrDefault((IBot ibot_0) => ibot_0.Name == string_4);
							if (bot2 != null)
							{
								comboBox_0.SelectedItem = bot2;
							}
						}
						if (comboBox_0.SelectedItem == null)
						{
							comboBox_0.SelectedItem = bots.FirstOrDefault();
						}
						method_14();
					});
					BotManager.OnBotChanged += method_6;
					RoutineManager.Load();
					base.Dispatcher.Invoke(delegate
					{
						foreach (IRoutine routine3 in RoutineManager.Routines)
						{
							method_2(routine3);
						}
					});
					comboBox_1.Dispatcher.BeginInvoke((Action)delegate
					{
						List<IRoutine> routines = RoutineManager.Routines;
						comboBox_1.ItemsSource = routines;
						if (CommandLine.Arguments.Exists("routine"))
						{
							string string_3 = CommandLine.Arguments.Single("routine");
							IRoutine routine = routines.FirstOrDefault((IRoutine iroutine_0) => iroutine_0.Name == string_3);
							if (routine != null)
							{
								comboBox_1.SelectedItem = routine;
							}
						}
						else if (!string.IsNullOrEmpty(MainSettings.Instance.LastRoutine))
						{
							string string_2 = MainSettings.Instance.LastRoutine;
							IRoutine routine2 = routines.FirstOrDefault((IRoutine iroutine_0) => iroutine_0.Name == string_2);
							if (routine2 != null)
							{
								comboBox_1.SelectedItem = routine2;
							}
						}
						if (comboBox_1.SelectedItem == null)
						{
							comboBox_1.SelectedItem = routines.FirstOrDefault();
						}
						method_14();
					});
					RoutineManager.OnRoutineChanged += method_7;
					PluginManager.Load();
					foreach (IPlugin plugin in PluginManager.Plugins)
					{
						if (MainSettings.Instance.EnabledPlugins.Contains(plugin.Name))
						{
							using (TritonHs.AcquireFrame())
							{
								PluginManager.Enable(plugin);
							}
							Thread.Sleep(20);
						}
						else
						{
							using (TritonHs.AcquireFrame())
							{
								PluginManager.Disable(plugin);
							}
							Thread.Sleep(20);
						}
					}
					listBox_0.Dispatcher.Invoke(() => listBox_0.ItemsSource = PluginManager.Plugins, DispatcherPriority.Normal);
					base.Dispatcher.Invoke(delegate
					{
						foreach (IPlugin plugin2 in PluginManager.Plugins)
						{
							method_2(plugin2);
						}
						method_14();
					});
					PluginManager.PluginEnabled += method_5;
					PluginManager.PluginDisabled += method_4;
					ilog_0.InfoFormat("{0}Please read the following guide before using this program:{0}https://www.thebuddyforum.com/hearthbuddy-forum/210230-hearthbuddy-bm-release-thread.html", Environment.NewLine);
					base.Dispatcher.Invoke(delegate
					{
						startButton.IsEnabled = true;
						comboBox_0.IsEnabled = true;
						comboBox_1.IsEnabled = true;
						button_1.IsEnabled = true;
						button_2.IsEnabled = true;
					});
					base.Dispatcher.Invoke(delegate
					{
						dispatcherTimer_1 = new DispatcherTimer(TimeSpan.FromMilliseconds(1000.0), DispatcherPriority.Normal, method_8, base.Dispatcher);
						dispatcherTimer_1.Start();
					});
					stopwatch_0.Restart();
					RoutineManager.OnRoutineChanged += method_7;
					BotManager.OnBotChanged += method_6;
					TritonHs.IsBotFullyLoaded = true;
					Hotkeys.Register("BotManager.StartStop", Keys.S, ModifierKeys.Alt | ModifierKeys.Shift, delegate
					{
						if (BotManager.IsRunning)
						{
							BotManager.Stop();
						}
						else
						{
							BotManager.Start();
						}
					});
					if (CommandLine.Arguments.Exists("autostart"))
					{
						BotManager.Start();
					}
				}
				else
				{
					string_ = $"This client version ({version}, {clientChangelist}) is unsupported. Hearthbuddy currently supports client version ({Class247.UInt32_1}, {Class247.UInt32_2}). Please check the forums for more information: https://www.thebuddyforum.com/hearthbuddy-forum/";
					ilog_0.ErrorFormat(string_);
					System.Windows.MessageBox.Show(string_, "Error", MessageBoxButton.OK, MessageBoxImage.Hand);
					base.Dispatcher.BeginInvoke(new Action(base.Close));
				}
			}
			catch (Exception exception)
			{
				ilog_0.Error("[OnStartup] A top-level exception has been caught.", exception);
			}
		}

		[CompilerGenerated]
		private void method_22()
		{
			if (!Class9.smethod_4(out mutex_0, out process_0))
			{
				ilog_0.Error("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.");
				System.Windows.MessageBox.Show(string.Format("Could not attach to a Hearthstone process. Please make sure an available Hearthstone process is running.{0}{0}Hearthbuddy will now close.", Environment.NewLine), "Hearthbuddy", MessageBoxButton.OK, MessageBoxImage.Hand);
			}
			else
			{
				dispatcherTimer_0 = new DispatcherTimer(TimeSpan.FromSeconds(1.0), DispatcherPriority.Normal, method_9, base.Dispatcher);
				dispatcherTimer_0.Start();
			}
		}

		[CompilerGenerated]
		private void method_23()
		{
			tabItem_0.DataContext = GlobalSettings.Instance;
		}

		[CompilerGenerated]
		private void method_24()
		{
			foreach (IBot bot in BotManager.Bots)
			{
				method_2(bot);
			}
		}

		[CompilerGenerated]
		private void method_25()
		{
			List<IBot> bots = BotManager.Bots;
			comboBox_0.ItemsSource = bots;
			if (CommandLine.Arguments.Exists("bot"))
			{
				string string_0 = CommandLine.Arguments.Single("bot");
				IBot bot = bots.FirstOrDefault((IBot ibot_0) => ibot_0.Name == string_0);
				if (bot != null)
				{
					comboBox_0.SelectedItem = bot;
				}
			}
			else if (!string.IsNullOrEmpty(MainSettings.Instance.LastBot))
			{
				string string_ = MainSettings.Instance.LastBot;
				IBot bot2 = bots.FirstOrDefault((IBot ibot_0) => ibot_0.Name == string_);
				if (bot2 != null)
				{
					comboBox_0.SelectedItem = bot2;
				}
			}
			if (comboBox_0.SelectedItem == null)
			{
				comboBox_0.SelectedItem = bots.FirstOrDefault();
			}
			method_14();
		}

		[CompilerGenerated]
		private void method_26()
		{
			foreach (IRoutine routine in RoutineManager.Routines)
			{
				method_2(routine);
			}
		}

		[CompilerGenerated]
		private void method_27()
		{
			List<IRoutine> routines = RoutineManager.Routines;
			comboBox_1.ItemsSource = routines;
			if (CommandLine.Arguments.Exists("routine"))
			{
				string string_0 = CommandLine.Arguments.Single("routine");
				IRoutine routine = routines.FirstOrDefault((IRoutine iroutine_0) => iroutine_0.Name == string_0);
				if (routine != null)
				{
					comboBox_1.SelectedItem = routine;
				}
			}
			else if (!string.IsNullOrEmpty(MainSettings.Instance.LastRoutine))
			{
				string string_ = MainSettings.Instance.LastRoutine;
				IRoutine routine2 = routines.FirstOrDefault((IRoutine iroutine_0) => iroutine_0.Name == string_);
				if (routine2 != null)
				{
					comboBox_1.SelectedItem = routine2;
				}
			}
			if (comboBox_1.SelectedItem == null)
			{
				comboBox_1.SelectedItem = routines.FirstOrDefault();
			}
			method_14();
		}

		[CompilerGenerated]
		private IEnumerable method_28()
		{
			return listBox_0.ItemsSource = PluginManager.Plugins;
		}

		[CompilerGenerated]
		private void method_29()
		{
			foreach (IPlugin plugin in PluginManager.Plugins)
			{
				method_2(plugin);
			}
			method_14();
		}

		[CompilerGenerated]
		private void method_30()
		{
			startButton.IsEnabled = true;
			comboBox_0.IsEnabled = true;
			comboBox_1.IsEnabled = true;
			button_1.IsEnabled = true;
			button_2.IsEnabled = true;
		}

		[CompilerGenerated]
		private void method_31()
		{
			dispatcherTimer_1 = new DispatcherTimer(TimeSpan.FromMilliseconds(1000.0), DispatcherPriority.Normal, method_8, base.Dispatcher);
			dispatcherTimer_1.Start();
		}

		[CompilerGenerated]
		private void method_32()
		{
			try
			{
				TritonHs.GuiTick(this);
			}
			catch (Exception exception)
			{
				ilog_0.Debug("[Ui] An exception was caught in BotGuiTimer:", exception);
			}
		}

		[CompilerGenerated]
		private void method_33()
		{
			stopwatch_0.Restart();
		}

		[CompilerGenerated]
		private void method_34()
		{
			startButton.IsEnabled = false;
			comboBox_1.IsEnabled = false;
			comboBox_0.IsEnabled = false;
			checkBox_0.IsEnabled = false;
			listBox_0.IsEnabled = false;
		}

		[CompilerGenerated]
		private void method_35()
		{
			stopwatch_0.Restart();
		}

		[CompilerGenerated]
		private void method_36()
		{
			startButton.IsEnabled = false;
			comboBox_1.IsEnabled = false;
			comboBox_0.IsEnabled = false;
			checkBox_0.IsEnabled = false;
			listBox_0.IsEnabled = false;
		}
	}
}
